<?php

class ml_tool_commentOutput
{
    /**
     * 格式化feed评论数据
     * @gaojian3
     * @param  array $comment_data
     * @return array $data
     */
    static  public function formatComment ($comment_data){
        if(!isset($oAccount)){
            $oAccount=new ml_model_dbUserAccount();
        }
        if(!isset($oIlike)){
            $oIlike=new ml_model_dbILike();
        }
        
        if(isset($comment_data['rid'])){
            $comment_data=array(
                0 => $comment_data
            );
        }
        foreach($comment_data as $val){
            $uids[]=$val['act_uid'];
        }
        $nicks=ml_tool_nick::uids2nicks($uids);
        
        foreach ($comment_data as $val){
            
            $value['rid']=$val['rid'];
            $value['uid']=$val['act_uid'];
            $value['comid']=$val['com_id'];
            
            $value['nick']=$nicks[$val['act_uid']];
            if(empty($value['nick'])){
                $oAccount->getAccountById($val['act_uid']);
                $accData=$oAccount->get_data(); 
                $value['nick']=$accData['nickname'];
            }
            $value['nick']=Tool_string::un_html($value['nick']);
            $value['headPic']=ml_tool_picid::uid2portrait($val['act_uid'],'sml');
            
            $value['time']=ml_tool_standardShow::time($val['ctime']);
            $value['comment']=ml_tool_formatContent::format_content($val['content']);
            $value['atti']=$oIlike->getAttByRid($val['act_uid'],$val['rid']);
            $value['atti']=$value['atti']['attitude'];
            $data[]=$value;
        }
        return $data ;
    }
    
    /**
     * 加载comment模板，组装html
     * @gaojian3
     * @param  array  $comment_data
     * @return string $aHtml
     */
    static public function parseCommentTpl($comment_data)
    {
        $data=self::formatComment($comment_data);
        
        foreach ($data as $val){
            $aHtml[] = ml_tool_template::parseModTpl($val , 'cmtMe');
        }
        return $aHtml;
    }
}